Imports System.Data.SqlClient
Imports System.Drawing
Imports DevExpress.XtraGrid
Imports DevExpress.XtraGrid.Views.Base
Imports DevExpress.XtraGrid.Columns
Imports DevExpress.XtraEditors
Imports DevExpress.XtraScheduler
Imports DevExpress.XtraScheduler.UI
'--- Created Date On : 06-Oct-2010 (Jagdish)

Public Class frmMotorSystem
    Dim VisitId As Integer
    Private IsSaved As Boolean = False

    Public Sub New(ByVal VisitId As Integer)
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call
        Me.VisitId = VisitId
    End Sub

    Private Sub frmMotorSystem_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        FillMotorSystemForm(VisitId)
    End Sub

    Private Sub FillMotorSystemForm(ByVal VisitId As Integer)
        Try
            '  fill form with info for that visit ,if it exist
            Dim strQuery As String = "SELECT  BulkText, InvoluntaryMovement, ToneULRight, ToneULLeft, ToneLLRight, " & _
                                        "ToneLLLeft, FingerAbdRight, FingerAbdLeft, FingerAddRight, FingerAddLeft, " & _
                                        "WristFlexRight, WristFlexLeft, WristExtRight, WristExtLeft, ElbowFlexRight, " & _
                                        "ElbowFlexLeft, ElbowExtRight, ElbowExtLeft, KneeFlexRight, KneeFlexLeft, " & _
                                        "KneeExtLeft, KneeExtRight, ShoulderFlexRight, ShoulderFlexLeft, " & _
                                        "ShoulderExtRight, ShoulderExtLeft, ShoulderAbdLeft, ShoulderAbdRight, " & _
                                        "ShoulderAddRight, HipFlexRight, ShoulderAddLeft, HipFlexLeft, HipExtRight, " & _
                                        "HipExtLeft, HipAbdRight, HipAbdLeft, HipAddRight, HipAddLeft, AnkleDorsiflexRight, " & _
                                        "AnkleDorsiflexLeft, AnklePlantarflexRight, AnklePlantarflexLeft FROM " & _
                                        "tblVisitNeurology WHERE VisitId= " & VisitId
            Dim dsTemp As DataSet = FillDataSet(strQuery)


            'no data,exit sub
            If dsTemp.Tables(0).Rows.Count > 0 Then
                With dsTemp.Tables(0)
                    txtBulk.Text = .Rows(0).Item("BulkText") & ""
                    txtInvoluntaryMovement.Text = .Rows(0).Item("InvoluntaryMovement") & ""
                    cmbToneULRight.SelectedItem = .Rows(0).Item("ToneULRight") & ""
                    cmbToneULLeft.SelectedItem = .Rows(0).Item("ToneULLeft") & ""
                    cmbToneLLRight.SelectedItem = .Rows(0).Item("ToneLLRight") & ""
                    cmbToneLLLeft.SelectedItem = .Rows(0).Item("ToneLLLeft") & ""
                    cmbFingerAbdRight.SelectedItem = .Rows(0).Item("FingerAbdright") & ""

                    cmbFingerAbdLeft.SelectedItem = .Rows(0).Item("FingerAbdLeft") & ""
                    cmbFingerAddRight.SelectedItem = .Rows(0).Item("FingerAddright") & ""
                    cmbFingerAddLeft.SelectedItem = .Rows(0).Item("FingerAddLeft") & ""
                    cmbWristFlexRight.SelectedItem = .Rows(0).Item("WristFlexRight") & ""
                    cmbWristFlexLeft.SelectedItem = .Rows(0).Item("WristFlexLeft") & ""
                    cmbWristExtRight.SelectedItem = .Rows(0).Item("WristExtRight") & ""
                    cmbWristExtLeft.SelectedItem = .Rows(0).Item("WristExtLeft") & ""
                    cmbElbowFlexRight.SelectedItem = .Rows(0).Item("ElbowFlexRight") & ""
                    cmbElbowFlexLeft.SelectedItem = .Rows(0).Item("ElbowFlexLeft") & ""
                    cmbElbowExtRight.SelectedItem = .Rows(0).Item("ElbowExtRight") & ""
                    cmbElbowExtLeft.SelectedItem = .Rows(0).Item("ElbowExtLeft") & ""
                    cmbKneeFlexRight.SelectedItem = .Rows(0).Item("KneeFlexRight") & ""
                    cmbKneeFlexLeft.SelectedItem = .Rows(0).Item("KneeFlexLeft") & ""
                    cmbKneeExtLeft.SelectedItem = .Rows(0).Item("KneeExtLeft") & ""
                    cmbKneeExtRight.SelectedItem = .Rows(0).Item("KneeExtRight") & ""
                    cmbShoulderFlexRight.SelectedItem = .Rows(0).Item("ShoulderFlexRight") & ""
                    cmbShoulderFlexLeft.SelectedItem = .Rows(0).Item("ShoulderFlexLeft") & ""
                    cmbShoulderExtRight.SelectedItem = .Rows(0).Item("ShoulderExtRight") & ""
                    cmbShoulderExtLeft.SelectedItem = .Rows(0).Item("ShoulderExtLeft") & ""
                    cmbShoulderAbdLeft.SelectedItem = .Rows(0).Item("ShoulderAbdLeft") & ""
                    cmbShoulderAbdRight.SelectedItem = .Rows(0).Item("ShoulderAbdright") & ""
                    cmbShoulderAddRight.SelectedItem = .Rows(0).Item("ShoulderAddright") & ""
                    cmbHipFlexRight.SelectedItem = .Rows(0).Item("HipFlexRight") & ""
                    cmbShoulderAddLeft.SelectedItem = .Rows(0).Item("ShoulderAddLeft") & ""
                    cmbHipFlexLeft.SelectedItem = .Rows(0).Item("HipFlexLeft") & ""
                    cmbHipExtRight.SelectedItem = .Rows(0).Item("HipExtRight") & ""
                    cmbHipExtLeft.SelectedItem = .Rows(0).Item("HipExtLeft") & ""
                    cmbHipAbdRight.SelectedItem = .Rows(0).Item("HipAbdright") & ""
                    cmbHipAbdLeft.SelectedItem = .Rows(0).Item("HipAbdLeft") & ""
                    cmbHipAddRight.SelectedItem = .Rows(0).Item("HipAddright") & ""
                    cmbHipAddLeft.SelectedItem = .Rows(0).Item("HipAddLeft") & ""
                    cmbAnkleDorsiflexRight.SelectedItem = .Rows(0).Item("AnkleDorsiflexRight") & ""
                    cmbAnkleDorsiflexLeft.SelectedItem = .Rows(0).Item("AnkleDorsiflexLeft") & ""
                    cmbAnklePlantarflexRight.SelectedItem = .Rows(0).Item("AnklePlantarflexRight") & ""
                    cmbAnklePlantarflexLeft.SelectedItem = .Rows(0).Item("AnklePlantarflexLeft") & ""
                End With
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Error)
            AddErrorLog("Error " & Err.Number & " (" & Err.Description & ") in Procedure " & _
                Reflection.MethodBase.GetCurrentMethod.Name & " Of " & Me.Name)
        End Try

    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        If blnSaveRecords() = False Then Exit Sub
        Me.Close()
        'If IsExitOnSave Then
        '    Me.Close()
        'End If

    End Sub

    Private Function blnSaveRecords() As Boolean
        blnSaveRecords = False
        Dim blnIsTransactionOpen As Boolean
        Dim strQuery As String
        Try
            gtrnWebPlusMed = gconWebPlusMed.BeginTransaction
            blnIsTransactionOpen = True
            Dim Cnt As Integer = Val(strRecordID("tblVisitNeurology", "VisitNeurologyId", "VisitId=" & VisitId))
            If Cnt > 0 Then
                strQuery = "BulkText =" & Trim(SmartReplace(txtBulk.Text) & "") & "" & _
                            ",InvoluntaryMovement =" & Trim(SmartReplace(txtInvoluntaryMovement.Text) & "") & "" & _
                            ",ToneULRight =" & Trim(SmartReplace(cmbToneULRight.SelectedItem) & "") & "" & _
                            ", ToneULLeft =" & Trim(SmartReplace(cmbToneULLeft.SelectedItem) & "") & "" & _
                            ", ToneLLRight =" & Trim(SmartReplace(cmbToneLLRight.SelectedItem) & "") & "" & _
                            ", ToneLLLeft =" & Trim(SmartReplace(cmbToneLLLeft.SelectedItem) & "") & "" & _
                            ", FingerAbdRight =" & Trim(SmartReplace(cmbFingerAbdRight.SelectedItem) & "") & "" & _
                            ", FingerAbdLeft =" & Trim(SmartReplace(cmbFingerAbdLeft.SelectedItem) & "") & "" & _
                            ", FingerAddRight =" & Trim(SmartReplace(cmbFingerAddRight.SelectedItem) & "") & "" & _
                            ", FingerAddLeft =" & Trim(SmartReplace(cmbFingerAddLeft.SelectedItem) & "") & "" & _
                            ", WristFlexRight =" & Trim(SmartReplace(cmbWristFlexRight.SelectedItem) & "") & "" & _
                            ", WristFlexLeft =" & Trim(SmartReplace(cmbWristFlexLeft.SelectedItem) & "") & "" & _
                            ", WristExtRight =" & Trim(SmartReplace(cmbWristExtRight.SelectedItem) & "") & "" & _
                            ", WristExtLeft =" & Trim(SmartReplace(cmbWristExtLeft.SelectedItem) & "") & "" & _
                            ", ElbowFlexRight =" & Trim(SmartReplace(cmbElbowFlexRight.SelectedItem) & "") & "" & _
                            ", ElbowFlexLeft =" & Trim(SmartReplace(cmbElbowFlexLeft.SelectedItem) & "") & "" & _
                            ", ElbowExtRight =" & Trim(SmartReplace(cmbElbowExtRight.SelectedItem) & "") & "" & _
                            ", ElbowExtLeft =" & Trim(SmartReplace(cmbElbowExtLeft.SelectedItem) & "") & "" & _
                            ", KneeFlexRight =" & Trim(SmartReplace(cmbKneeFlexRight.SelectedItem) & "") & "" & _
                            ", KneeFlexLeft =" & Trim(SmartReplace(cmbKneeFlexLeft.SelectedItem) & "") & "" & _
                            ", KneeExtRight =" & Trim(SmartReplace(cmbKneeExtRight.SelectedItem) & "") & "" & _
                            ", KneeExtLeft =" & Trim(SmartReplace(cmbKneeExtLeft.SelectedItem) & "") & "" & _
                            ", ShoulderFlexRight =" & Trim(SmartReplace(cmbShoulderFlexRight.SelectedItem) & "") & "" & _
                            ", ShoulderFlexLeft =" & Trim(SmartReplace(cmbShoulderFlexLeft.SelectedItem) & "") & "" & _
                            ", ShoulderExtRight =" & Trim(SmartReplace(cmbShoulderExtRight.SelectedItem) & "") & "" & _
                            ", ShoulderExtLeft =" & Trim(SmartReplace(cmbShoulderExtLeft.SelectedItem) & "") & "" & _
                            ", ShoulderAbdRight =" & Trim(SmartReplace(cmbShoulderAbdRight.SelectedItem) & "") & "" & _
                            ", ShoulderAbdLeft =" & Trim(SmartReplace(cmbShoulderAbdLeft.SelectedItem) & "") & "" & _
                            ", ShoulderAddRight =" & Trim(SmartReplace(cmbShoulderAddRight.SelectedItem) & "") & "" & _
                            ", ShoulderAddLeft =" & Trim(SmartReplace(cmbShoulderAddLeft.SelectedItem) & "") & "" & _
                            ", HipFlexRight =" & Trim(SmartReplace(cmbHipFlexRight.SelectedItem) & "") & "" & _
                            ", HipFlexLeft =" & Trim(SmartReplace(cmbHipFlexLeft.SelectedItem) & "") & "" & _
                            ", HipExtRight =" & Trim(SmartReplace(cmbHipExtRight.SelectedItem) & "") & "" & _
                            ", HipExtLeft =" & Trim(SmartReplace(cmbHipExtLeft.SelectedItem) & "") & "" & _
                            ", HipAbdRight =" & Trim(SmartReplace(cmbHipAbdRight.SelectedItem) & "") & "" & _
                            ", HipAbdLeft =" & Trim(SmartReplace(cmbHipAbdLeft.SelectedItem) & "") & "" & _
                            ", HipAddRight =" & Trim(SmartReplace(cmbHipAddRight.SelectedItem) & "") & "" & _
                            ", HipAddLeft =" & Trim(SmartReplace(cmbHipAddLeft.SelectedItem) & "") & "" & _
                            ", AnkleDorsiflexRight =" & Trim(SmartReplace(cmbAnkleDorsiflexRight.SelectedItem) & "") & "" & _
                            ", AnkleDorsiflexLeft =" & Trim(SmartReplace(cmbAnkleDorsiflexLeft.SelectedItem) & "") & "" & _
                            ", AnklePlantarflexRight =" & Trim(SmartReplace(cmbAnklePlantarflexRight.SelectedItem) & "") & "" & _
                            ", AnklePlantarflexLeft =" & Trim(SmartReplace(cmbAnklePlantarflexLeft.SelectedItem) & "") & ""
                Call UpdateTable("tblVisitNeurology", strQuery, "VisitId=" & VisitId)
            Else
                strQuery = VisitId & _
                            ",Null,Null,Null,Null,Null,Null,Null,Null,Null,Null,Null,Null,Null,Null,Null,Null,Null " & _
                            ",Null,Null,Null,Null,Null,Null,Null,Null,Null,Null,Null,Null,Null,Null,Null,Null,Null,NUll " & _
                            "," & Trim(SmartReplace(txtBulk.Text) & "") & "" & _
                            "," & Trim(SmartReplace(txtInvoluntaryMovement.Text) & "") & "" & _
                            "," & Trim(SmartReplace(cmbToneULRight.SelectedItem) & "") & "" & _
                            "," & Trim(SmartReplace(cmbToneULLeft.SelectedItem) & "") & "" & _
                            "," & Trim(SmartReplace(cmbToneLLRight.SelectedItem) & "") & "" & _
                            "," & Trim(SmartReplace(cmbToneLLLeft.SelectedItem) & "") & "" & _
                            "," & Trim(SmartReplace(cmbFingerAbdRight.SelectedItem) & "") & "" & _
                            "," & Trim(SmartReplace(cmbFingerAbdLeft.SelectedItem) & "") & "" & _
                            "," & Trim(SmartReplace(cmbFingerAddRight.SelectedItem) & "") & "" & _
                            "," & Trim(SmartReplace(cmbFingerAddLeft.SelectedItem) & "") & "" & _
                            "," & Trim(SmartReplace(cmbWristFlexRight.SelectedItem) & "") & "" & _
                            "," & Trim(SmartReplace(cmbWristFlexLeft.SelectedItem) & "") & "" & _
                            "," & Trim(SmartReplace(cmbWristExtRight.SelectedItem) & "") & "" & _
                            "," & Trim(SmartReplace(cmbWristExtLeft.SelectedItem) & "") & "" & _
                            "," & Trim(SmartReplace(cmbElbowFlexRight.SelectedItem) & "") & "" & _
                            "," & Trim(SmartReplace(cmbElbowFlexLeft.SelectedItem) & "") & "" & _
                            "," & Trim(SmartReplace(cmbElbowExtRight.SelectedItem) & "") & "" & _
                            "," & Trim(SmartReplace(cmbElbowExtLeft.SelectedItem) & "") & "" & _
                            "," & Trim(SmartReplace(cmbKneeFlexRight.SelectedItem) & "") & "" & _
                            "," & Trim(SmartReplace(cmbKneeFlexLeft.SelectedItem) & "") & "" & _
                            "," & Trim(SmartReplace(cmbKneeExtRight.SelectedItem) & "") & "" & _
                            "," & Trim(SmartReplace(cmbKneeExtLeft.SelectedItem) & "") & "" & _
                            "," & Trim(SmartReplace(cmbShoulderFlexRight.SelectedItem) & "") & "" & _
                            "," & Trim(SmartReplace(cmbShoulderFlexLeft.SelectedItem) & "") & "" & _
                            "," & Trim(SmartReplace(cmbShoulderExtRight.SelectedItem) & "") & "" & _
                            "," & Trim(SmartReplace(cmbShoulderExtLeft.SelectedItem) & "") & "" & _
                            "," & Trim(SmartReplace(cmbShoulderAbdRight.SelectedItem) & "") & "" & _
                            "," & Trim(SmartReplace(cmbShoulderAbdLeft.SelectedItem) & "") & "" & _
                            "," & Trim(SmartReplace(cmbShoulderAddRight.SelectedItem) & "") & "" & _
                            "," & Trim(SmartReplace(cmbShoulderAddLeft.SelectedItem) & "") & "" & _
                            "," & Trim(SmartReplace(cmbHipFlexRight.SelectedItem) & "") & "" & _
                            "," & Trim(SmartReplace(cmbHipFlexLeft.SelectedItem) & "") & "" & _
                            "," & Trim(SmartReplace(cmbHipExtRight.SelectedItem) & "") & "" & _
                            "," & Trim(SmartReplace(cmbHipExtLeft.SelectedItem) & "") & "" & _
                            "," & Trim(SmartReplace(cmbHipAbdRight.SelectedItem) & "") & "" & _
                            "," & Trim(SmartReplace(cmbHipAbdLeft.SelectedItem) & "") & "" & _
                            "," & Trim(SmartReplace(cmbHipAddRight.SelectedItem) & "") & "" & _
                            "," & Trim(SmartReplace(cmbHipAddLeft.SelectedItem) & "") & "" & _
                            "," & Trim(SmartReplace(cmbAnkleDorsiflexRight.SelectedItem) & "") & "" & _
                            "," & Trim(SmartReplace(cmbAnkleDorsiflexLeft.SelectedItem) & "") & "" & _
                            "," & Trim(SmartReplace(cmbAnklePlantarflexRight.SelectedItem) & "") & "" & _
                            "," & Trim(SmartReplace(cmbAnklePlantarflexLeft.SelectedItem) & "") & ""
                Call InsertintoTable("tblVisitNeurology", strQuery)
            End If

            gtrnWebPlusMed.Commit()
            blnIsTransactionOpen = False
            blnSaveRecords = True
        Catch ex As Exception
            If blnIsTransactionOpen = True Then
                gtrnWebPlusMed.Rollback()
            End If
            MessageBox.Show(ex.Message, gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Error)
            AddErrorLog("Error " & Err.Number & " (" & Err.Description & ") in Procedure " & _
                Reflection.MethodBase.GetCurrentMethod.Name & " Of " & Me.Name)
        End Try
    End Function

    Private Sub btnNeurologyDefaultValues_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNeurologyDefaultValues.Click
        txtBulk.Text = "NAD"
        txtInvoluntaryMovement.Text = "NAD"

        cmbToneULRight.SelectedItem = "Normal"
        cmbToneULLeft.SelectedItem = "Normal"
        cmbToneLLRight.SelectedItem = "Normal"
        cmbToneLLLeft.SelectedItem = "Normal"

        cmbFingerAbdRight.SelectedItem = "5/5"
        cmbFingerAbdLeft.SelectedItem = "5/5"
        cmbFingerAddRight.SelectedItem = "5/5"
        cmbFingerAddLeft.SelectedItem = "5/5"

        cmbWristFlexRight.SelectedItem = "5/5"
        cmbWristFlexLeft.SelectedItem = "5/5"
        cmbWristExtRight.SelectedItem = "5/5"
        cmbWristExtLeft.SelectedItem = "5/5"

        cmbElbowFlexRight.SelectedItem = "5/5"
        cmbElbowFlexLeft.SelectedItem = "5/5"
        cmbElbowExtRight.SelectedItem = "5/5"
        cmbElbowExtLeft.SelectedItem = "5/5"

        cmbKneeFlexRight.SelectedItem = "5/5"
        cmbKneeFlexLeft.SelectedItem = "5/5"
        cmbKneeExtLeft.SelectedItem = "5/5"
        cmbKneeExtRight.SelectedItem = "5/5"

        cmbShoulderFlexRight.SelectedItem = "5/5"
        cmbShoulderFlexLeft.SelectedItem = "5/5"
        cmbShoulderExtRight.SelectedItem = "5/5"
        cmbShoulderExtLeft.SelectedItem = "5/5"
        cmbShoulderAbdLeft.SelectedItem = "5/5"
        cmbShoulderAbdRight.SelectedItem = "5/5"
        cmbShoulderAddRight.SelectedItem = "5/5"
        cmbShoulderAddLeft.SelectedItem = "5/5"

        cmbHipFlexRight.SelectedItem = "5/5"
        cmbHipFlexLeft.SelectedItem = "5/5"
        cmbHipExtRight.SelectedItem = "5/5"
        cmbHipExtLeft.SelectedItem = "5/5"
        cmbHipAbdRight.SelectedItem = "5/5"
        cmbHipAbdLeft.SelectedItem = "5/5"
        cmbHipAddRight.SelectedItem = "5/5"
        cmbHipAddLeft.SelectedItem = "5/5"

        cmbAnkleDorsiflexRight.SelectedItem = "5/5"
        cmbAnkleDorsiflexLeft.SelectedItem = "5/5"
        cmbAnklePlantarflexRight.SelectedItem = "5/5"
        cmbAnklePlantarflexLeft.SelectedItem = "5/5"
    End Sub

    Private Sub txtBulk_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtBulk.KeyDown, txtInvoluntaryMovement.KeyDown
        If e.KeyCode = Keys.Enter Then
            Call NotesFocus(txtBulk.Text)
        End If
    End Sub

    Private Sub txtBulk_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtBulk.Validated, txtInvoluntaryMovement.Validated
        sender.text = TrimX(sender.text)
    End Sub
End Class
